//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2003 Intrinsyc Europe Ltd.
//////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2004 Siemens AG
//
// Version: 1.1.2.5
// Date:    11. Jan. 2006
//////////////////////////////////////////////////////////////////////////////


#pragma once

#define SECUR_CMDBUF_LENGTH      (MAX_ATCMD_LEN)
// We do not need this calculation: any string from or to the AT interface will not exceed MAX_ATCMD_LEN character
//#define SECUR_CMDBUF_LENGTH      (MAX_PATH + 2 * MAXLENGTH_PASSWORD)

// Maximum length of the PIN2 password.
#ifdef RIL_USE_CPIN2_WORKAROUND
#define MAXLEN_PIN2     8
#endif

//
// Locked states
//
// Please notice: Microsoft had confused the meanings of PH-NET PUK and PH-NET PIN
// (Customer SIM-Lock), so they are swaped intentionally in the table below. Please 
// notice also, that the PH-NET PIN dialog is only available for Smartphone.
//
const LPCSTR g_rgszLockedStates[] =
{
    "",                 // RIL_LOCKEDSTATE_UNKNOWN
    "READY",            // RIL_LOCKEDSTATE_READY
    "SIM PIN",          // RIL_LOCKEDSTATE_SIM_PIN
    "SIM PUK",          // RIL_LOCKEDSTATE_SIM_PUK
    "PH-SIM PIN",       // RIL_LOCKEDSTATE_PH_SIM_PIN
    "PH-FSIM PIN",      // RIL_LOCKEDSTATE_PH_FSIM_PIN
    "PH-FSIM PUK",      // RIL_LOCKEDSTATE_PH_FSIM_PUK
    "SIM PIN2",         // RIL_LOCKEDSTATE_SIM_PIN2
    "SIM PUK2",         // RIL_LOCKEDSTATE_SIM_PUK2
    "PH-NET PUK",       // RIL_LOCKEDSTATE_PH_NET_PIN, see comment above
    "PH-NET PIN",       // RIL_LOCKEDSTATE_PH_NET_PUK, see comment above
    "PH-NETSUB PIN",    // RIL_LOCKEDSTATE_PH_NETSUB_PIN
    "PH-NETSUB PUK",    // RIL_LOCKEDSTATE_PH_NETSUB_PUK
    "PH-SP PIN",        // RIL_LOCKEDSTATE_PH_SP_PIN
    "PH-SP PUK",        // RIL_LOCKEDSTATE_PH_SP_PUK
    "PH-CORP PIN",      // RIL_LOCKEDSTATE_PH_CORP_PIN
    "PH-CORP PUK",      // RIL_LOCKEDSTATE_PH_COPR_PUK
};
#define NUM_LOCKEDSTATES     (sizeof(g_rgszLockedStates) / sizeof(LPCSTR) - 1)


//
// Lock facilities
//
static const LPCSTR g_rgszLockFacilities[] =
{
    "",     // 0
    "CS",   // RIL_LOCKFACILITY_CNTRL
    "PS",   // RIL_LOCKFACILITY_PH_SIM
    "PF",   // RIL_LOCKFACILITY_PH_FSIM
    "SC",   // RIL_LOCKFACILITY_SIM
    "P2",   // RIL_LOCKFACILITY_SIM_PIN2
    "FD",   // RIL_LOCKFACILITY_SIM_FIXEDIALING
    "PN",   // RIL_LOCKFACILITY_NETWORKPERS
    "PU",   // RIL_LOCKFACILITY_NETWORKSUBPERS
    "PP",   // RIL_LOCKFACILITY_SERVICEPROVPERS
    "PC",   // RIL_LOCKFACILITY_CORPPERS

};
#define NUM_LOCKFACILITIES    (sizeof(g_rgszLockFacilities) / sizeof(LPCSTR))


//
// Call barring types
//
static const LPCSTR g_rgszBarringTypes[] =
{
    "",     // 0
    "AO",   // RIL_BARRTYPE_ALLOUTGOING
    "OI",   // RIL_BARRTYPE_OUTGOINGINT
    "OX",   // RIL_BARRTYPE_OUTGOINGINTEXTOHOME
    "AI",   // RIL_BARRTYPE_ALLINCOMING
    "IR",   // RIL_BARRTYPE_INCOMINGROAMING
    "NS",   // RIL_BARRTYPE_INCOMINGNOTINSIM
    "AB",   // RIL_BARRTYPE_ALLBARRING
    "AG",   // RIL_BARRTYPE_ALLOUTGOINGBARRING
    "AC",   // RIL_BARRTYPE_ALLINCOMINGBARRING

};
#define NUM_BARRINGTYPES    (sizeof(g_rgszBarringTypes) / sizeof(LPCSTR))

//
// Translation table Barring Type -> *#-Code
//
#define RIL_BARRINGSTATUS_QUERY                   (0x000000FF)

struct BARRING2ATD
{
    DWORD dwBarringType;
    DWORD dwBarringStatus;
    char  szATD[8];
};

static const BARRING2ATD g_rgBarringTypeTable[] =
{
    {RIL_BARRTYPE_ALLOUTGOING, RIL_BARRINGSTATUS_ENABLED,  "*33"},
    {RIL_BARRTYPE_ALLOUTGOING, RIL_BARRINGSTATUS_DISABLED, "#33"},
    {RIL_BARRTYPE_ALLOUTGOING, RIL_BARRINGSTATUS_QUERY,    "*#33"},
    {RIL_BARRTYPE_OUTGOINGINT, RIL_BARRINGSTATUS_ENABLED,  "*331"},
    {RIL_BARRTYPE_OUTGOINGINT, RIL_BARRINGSTATUS_DISABLED, "#331"},
    {RIL_BARRTYPE_OUTGOINGINT, RIL_BARRINGSTATUS_QUERY,     "*#331"},
    {RIL_BARRTYPE_OUTGOINGINTEXTOHOME, RIL_BARRINGSTATUS_ENABLED,  "*332"},
    {RIL_BARRTYPE_OUTGOINGINTEXTOHOME, RIL_BARRINGSTATUS_DISABLED, "#332"},
    {RIL_BARRTYPE_OUTGOINGINTEXTOHOME, RIL_BARRINGSTATUS_QUERY,    "*#332"},
    {RIL_BARRTYPE_ALLINCOMING, RIL_BARRINGSTATUS_ENABLED,  "*35"},
    {RIL_BARRTYPE_ALLINCOMING, RIL_BARRINGSTATUS_DISABLED, "#35"},
    {RIL_BARRTYPE_ALLINCOMING, RIL_BARRINGSTATUS_QUERY,    "*#35"},
    {RIL_BARRTYPE_INCOMINGROAMING, RIL_BARRINGSTATUS_ENABLED,  "*351"},
    {RIL_BARRTYPE_INCOMINGROAMING, RIL_BARRINGSTATUS_DISABLED, "#351"},
    {RIL_BARRTYPE_INCOMINGROAMING, RIL_BARRINGSTATUS_QUERY,    "*#351"},
    {RIL_BARRTYPE_ALLBARRING, RIL_BARRINGSTATUS_DISABLED, "#330"},
    {RIL_BARRTYPE_ALLOUTGOINGBARRING, RIL_BARRINGSTATUS_DISABLED, "#333"},
    {RIL_BARRTYPE_ALLINCOMINGBARRING, RIL_BARRINGSTATUS_DISABLED, "#353"}
};
#define NUM_BARRING_VALUES    (sizeof(g_rgBarringTypeTable) / sizeof(BARRING2ATD))


HRESULT RILDrv_GetUserIdentity(DWORD dwParam);
HRESULT RILDrv_GetPhoneLockedState(DWORD dwParam);
HRESULT RILDrv_UnlockPhone(DWORD dwParam, LPCSTR lpszPassword, LPCSTR lpszNewPassword);
HRESULT RILDrv_GetLockingStatus(DWORD dwParam, DWORD dwFacility, LPCSTR lpszPassword);
HRESULT RILDrv_SetLockingStatus(DWORD dwParam, DWORD dwFacility, LPCSTR lpszPassword, DWORD dwStatus);
HRESULT RILDrv_ChangeLockingPassword(DWORD dwParam, DWORD dwFacility, DWORD dwOldPasswordType, LPCSTR lpszOldPassword, LPCSTR lpszNewPassword);
HRESULT RILDrv_GetCallBarringStatus(DWORD dwParam, DWORD dwType, DWORD dwInfoClass, LPCSTR lpszPassword);
HRESULT RILDrv_SetCallBarringStatus(DWORD dwParam, DWORD dwType, DWORD dwInfoClass, LPCSTR lpszPassword, DWORD dwStatus);
HRESULT RILDrv_ChangeCallBarringPassword(DWORD dwParam, DWORD dwType, LPCSTR lpszOldPassword, LPCSTR lpszNewPassword);


